package com.qltv.main;

import org.apache.log4j.Logger;

import com.qltv.menu.Button;
import com.qltv.menu.CommonButton;
import com.qltv.menu.ComplexButton;
import com.qltv.menu.Menu;
import com.qltv.pojo.AccessToken;
import com.qltv.utils.WeixinUtil;

/**
 * 
 * 类名：MenuManager
 * 描述：菜单管理器类
 * @author telnet
 * 创建时间：2018年1月12日
 */
public class MenuManager {
	
	public static final Logger logger = Logger.getLogger(MenuManager.class);
	
	public static void main(String[] args) {
		String appid = "wx314b84ea36660a09";
		String appsecret = "98ee5ea48ec9f8763792ab1c0bbe5576";
		
		AccessToken access_token = WeixinUtil.getAccessToken(appid, appsecret);
		if(null!=access_token){
			int result = WeixinUtil.createMenu(getMenu(), access_token.getToken());
			if(0==result){
				logger.info("菜单创建成功！");
			}else{
				logger.info("菜单创建失败，错误码："+result);
			}
		}
	}
	
	private static Menu getMenu(){
		CommonButton btn11 = new CommonButton();
		btn11.setName("天气预报");
		btn11.setType("click");
		btn11.setKey("11");
		
		CommonButton btn12 = new CommonButton();
		btn12.setName("12306");
		btn12.setType("click");
		btn12.setKey("12");
		
		
		CommonButton btn21 = new CommonButton();
		btn21.setName("党建平台");
		btn21.setType("click");
		btn21.setKey("21");
		
		ComplexButton mainBtn1 = new ComplexButton();
		mainBtn1.setName("实用工具");
		mainBtn1.setSub_button(new CommonButton[]{btn11,btn12});
		
		ComplexButton mainBtn2 = new ComplexButton();
		mainBtn2.setName("党建工作");
		mainBtn2.setSub_button(new CommonButton[]{btn21});
		
		
		Menu menu= new Menu();
		menu.setButton(new Button[]{mainBtn1,mainBtn2});
		
		return menu;
		
	}

}
